import {Module} from "@nestjs/common";
import {MailerModule} from "@nestjs-modules/mailer";
import {ConfigService} from "@nestjs/config";
import {MailService} from "./mail.service";

@Module({
    imports: [
        MailerModule.forRootAsync({
            useFactory: (configService:ConfigService) => ({
                transport: {
                    host: configService.get<string>("mail.transport.host"),
                    port: configService.get<number>("mail.transport.port"),
                    secure: configService.get<boolean>("mail.transport.secure"),
                    auth: {
                        user: configService.get<string>("mail.transport.auth.user"),
                        pass: configService.get<string>("mail.transport.auth.pass"),
                    }
                },
                options: {
                    timeout: 4000 // 超时时间设置
                },
                defaults: {
                    from: configService.get<string>("mail.defaults.from"),
                },
            }),
            inject: [ConfigService]
        }),
    ],
    providers: [MailService],
    exports: [MailService]
})
export class MailModule {
}
